package com.yzzrjy.controller.mainservlet.blog;

import com.yzzrjy.Service.BlogService;
import com.yzzrjy.util.ResponseUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "PublishBlogServlet", value = "/publishBlog")
public class PublishBlogServlet extends HttpServlet {
    private BlogService blogService = new BlogService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uid = request.getParameter("uid");
        String token = request.getParameter("token");
        String text = request.getParameter("text");
        String content = request.getParameter("content");
        String type = request.getParameter("type");
        String city = request.getParameter("city");
        if(uid == null || token == null || content == null || type == null){
            ResponseUtils.parameterError(response);
            return;
        }

        try {
            blogService.addBlog(uid, text, content, Byte.parseByte(type), city);
            ResponseUtils.success(response, "success");
        } catch (SQLException | RuntimeException e) {
            ResponseUtils.otherError(response, "动态发布失败");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
